package com.adong.mapper;

import com.adong.domain.Order;
import com.adong.domain.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author com.adong
 */
public interface OrderMapper {

    /* @Select("SELECT *,o.id AS oid FROM USER u JOIN orders o ON u.`id` = o.`uid`")
     @Results({
             @Result(column = "oid",property = "id"),
             @Result(column = "ordertime",property = "ordertime"),
             @Result(column = "total",property = "total"),
             @Result(column = "uid",property = "user.id"),
             @Result(column = "username",property = "user.username"),
             @Result(column = "password",property = "user.password"),

     })
     List<Order> findAll();*/

    @Select("select * from orders")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "ordertime", column = "ordertime"),
            @Result(property = "total", column = "total"),
            @Result(
                    property = "user", //属性名称
                    column = "uid", //根据那个字段查询user表的数据
                    javaType = User.class,//要封装的实体类型
                    one = @One(select = "com.adong.mapper.UserMapper.findById"))
    })
    List<Order> findAll();
}
